﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FMSpaceShooter.Screens;
using FMSpaceShooter.Util;

namespace FMSpaceShooter.GameObjects
{
    abstract class EnemyBase : ObjectBase 
    {
        public const string TypeName = "BaseEnemy";
        public virtual int Points { get { return 10; } }
        public override bool IsFriendly { get { return false; } }
        public virtual bool isDead { get { return dead; } }
        private bool dead = false;
        private bool isHit=false;

        public EnemyBase(GameplayScreen screen, string textureName, Vector2 initialLocation, int enemyHp, Vector2? enemySize = null)
            : base(screen, textureName, enemySize)
        {
            position = initialLocation;
            hp = enemyHp;
        }

        public override void Die()
        {
            if (!isDead)
            {
                base.Die();
                screen.GOM.Level.enemyCount -= 1;
                screen.GOM.AddPoints(Points);
                dead = true;
                
            }
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);


            if (isHit)
            {
                isHit = false;
            }
        }

        public override void Hit(int damage)
        {
            base.Hit(damage);
            isHit=true;
        }

        public override void Draw(GameTime gameTime)
        {

            SpriteBatch spriteBatch = screen.ScreenManager.SpriteBatch;



            if (isHit)
            {
                spriteBatch.Draw(texture, position, null, new Color(255, 0, 0),
                    rotation, origin, scale, SpriteEffects.None, 0);
            }
            else
            {
                spriteBatch.Draw(texture, position, null, Color.White, 
                    rotation, origin, scale, SpriteEffects.None, 0);
            }

            if (isDead)
            {
                spriteBatch.Draw(screen.GOM.GetTexture("Images/Bullets/Explosion1"), position, null, Color.Red,
                 rotation, Tools.GetTextureVector(screen.GOM.GetTexture("Images/Bullets/Explosion1"))/2, 3, SpriteEffects.None, 0);
            }

        }
    }
}
